package com.leetcode;

/**
 * 125. 验证回文串
 * 双索引指针
 */
public class Solution125_1 {

    public boolean isPalindrome(String s) {
        int n = s.length();
        StringBuffer words = new StringBuffer(n);
        for (int i = 0; i < n; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                words.append(Character.toLowerCase(ch));
            }
        }
        StringBuffer revWords = new StringBuffer(words).reverse();
        return words.toString().equals(revWords.toString());
    }

    public static void main(String[] args) {
        String s = "A man, a plan, a canal: Panama";
//        String s = "0P";
        boolean res = new Solution125_1().isPalindrome(s);
        System.out.println(res);
    }

}
